const alphabetPool = [];
for (let i = 0; i < 26; i++) {
    if (i<10) {
        alphabetPool.push(String.fromCharCode(48+i));
    }
    alphabetPool.push(String.fromCharCode(65+i));
    alphabetPool.push(String.fromCharCode(97+i));
}

function randomInt(minNum,maxNum) {
    switch(arguments.length){
        case 1:
            return Math.floor(Math.random()*minNum);
        case 2:
            return Math.floor(Math.random()*(maxNum-minNum+1))+minNum;
        default:
            return 0;
    } 
}

function randomFloat(minNum,maxNum) {
    switch(arguments.length){
        case 1:
            return Math.random()*minNum;
        case 2:
            return Math.random()*(maxNum-minNum)+minNum;
        default:
            return 0;
    } 
}

function randomBool() {
    return Math.random()<0.5;
}

//生成随机密码，数字+英文大小写
function randomPassword(count) {
    let ret = "";
    for (let i = 0; i < count; i++) {
        let rd = randomInt(alphabetPool.length);
        if (rd < alphabetPool.length) {
            ret += alphabetPool[rd];
        }
    }
    return ret;
}

module.exports.randomInt = randomInt;
module.exports.randomFloat = randomFloat;
module.exports.randomBool = randomBool;
module.exports.randomPassword = randomPassword;
